package jdbc;

import jdbc.bean.Student;
import jdbc.dao.StudentJDBCTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class JdbcApp {
    public static void main(String[] args) {
        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jdbc\\beans.xml");
        final StudentJDBCTemplate studentTemplate = (StudentJDBCTemplate) context.getBean("studentTemplate");
        // add
        studentTemplate.create("john",22);
        studentTemplate.create("tom",23);
        studentTemplate.create("张三",24);
        // getall
        final List<Student> students = studentTemplate.listStudents();
        for (Student student : students) {
            System.out.println(student);
        }
        //update
        studentTemplate.update(2,44);
        // get
        final Student student = studentTemplate.getStudent(2);
        System.out.println(student);
    }
}
